# scheduler/apps.py
from django.apps import AppConfig
from django.utils.module_loading import import_module

class SchedulerConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'ctbloge.apps.schedulers'

    def ready(self):
        from ctbloge.apps.schedulers.models import TaskRegistry, ScheduledTask
        from django.apps import apps
        # 注册任务
        for app_config in apps.get_app_configs():
            tasks_module = f"{app_config.name}.tasks"
            try:
                # 自动加载 tasks.py 模块
                import_module(tasks_module)
            except ModuleNotFoundError as e:
                if "No module named" not in str(e):
                    print(f"加载任务模块异常: {tasks_module} - {e}")

